using System;
using System.Configuration;
using System.Data;
using digit.Core;


namespace SMS.SmManager
{
    public class ProcessLogsManager
    {
        #region CONSTRUCTORS
        static ProcessLogsManager()
        {
            _data = new ProcessLogsData(Util.GetConnectionString("SMSC"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static ProcessLogsData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string errMsg)
        {
            _error = "";
            try
            {
                object[] values = new object[1];
                values[0] = Util.ReplaceNullTo(errMsg, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(ProcessLogsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[1];
                values[0] = Util.ReplaceNullTo(info.ErrMsg, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(int logID, string errMsg)
        {
            _error = "";
            try
            {
                object[] values = new object[2];
                values[0] = logID;
                values[1] = Util.ReplaceNullTo(errMsg, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(ProcessLogsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[2];
                values[0] = info.LogID;
                values[1] = Util.ReplaceNullTo(info.ErrMsg, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(int logID)
        {
            _error = "";
            try
            {
                object[] values = { logID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(ProcessLogsInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.LogID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static ProcessLogsInfo Select(int logID)
        {
            _error = "";
            try
            {
                object[] values = { logID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                ProcessLogsInfo info = new ProcessLogsInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}